<?php

namespace App\Http\Controllers\Admin\Badge;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;    //引用http请求类
use App\Response\Response;

class BadgeExchangeController extends BaseController
{
    /**
     * @api {get} /badge/reward 领取奖励列表
     * @apiVersion 0.1.0
     * @apiName 徽章管理-领取奖励列表
     * @apiGroup 徽章管理
     *
     * @apiParam {number} user_code 用户编号 可选
     * @apiParam {number} page 当前页数 可选
     * @apiParam {number} perPage 分页容量 可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
    "code": 200,
    "data": {
        "list": [
            {
                "id(序号)": 68,
                "nickname(昵称)": "小爷我来了来了哈哈哈",
                "user_code(用户编号)": 356165,
                "goods_name(奖励名称)": "小爷我来了来了哈哈哈",
                "number(所需徽章数量)": "学霸徽章",
                "add_time(获得时间)": "2020-11-04 09:59:58"
            }
        ],
        "meta": {
                "page": 1,
                "limit": 10,
                "next": null,
                "total": 1
            }
        }
     }
     *
     *
     */
    public function list(Request $request) {
        //参数校验
        $v = app('validator')->make($request->all(), [
                'user_code' => 'filled|numeric',
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $list = app('repo_badge')->getBadgeExchangeQueryList($request->input());

        return Response::sendList($list);
    }

}
